// const originArr = ''

// function countAndSay (n) {

// }

// console.log(countAndSay(originArr))

function Node (element) {
  this.element = element
  this.next = null
  this.previous = null
}

function find (item) {
  let currNode = this.head
  while (currNode.element !== item) {
    currNode = currNode.next
  }
  return currNode
}

function insert (newElement, item) {
  const newNode = new Node(newElement)
  const current = this.find(item)
  if (current.next !== null) current.next.previous = newNode
  newNode.next = current.next
  newNode.previous = current
  current.next = newNode
}

function display () {
  let current = this.head
  while (current.next !== null) {
    console.log(current.next.element)
    current = current.next
  }
}

function remove (item) {
  const current = this.find(item)
  const prve = current.previous
  if (current.next !== null) {
    current.next.previous = prve
    prve.next = current.next
  } else {
    prve.next = null
  }
}

function findLast () {
  let currNode = this.head
  while (currNode.next !== null) {
    currNode = currNode.next
  }

  return currNode
}

function dispReverse () {
  let currNode = this.head
  currNode = this.findLast()
  while (currNode.previous !== null) {
    console.log(currNode.element)
    currNode = currNode.previous
  }
}

function back (n) {
  let i = 0
  while (i < n && this.node.next !== null) {
    this.node = this.node.next
    i++
  }
}

function advance (n) {
  let i = 0
  while(i < n && this.node.previous.element !== this.head.element) {
    this.node = this.node.previous
    i++
  }
}

function show () {
  console.log(this.node);
}

function LList () {
  this.head = new Node('head')
  this.node = this.head
  this.find = find
  this.insert = insert
  this.display = display
  this.remove = remove
  this.findLast = findLast
  this.dispReverse = dispReverse
  this.back = back
  this.advance = advance
  this.show = show
}


const cities = new LList()
cities.insert('Conway', 'head')
cities.insert('Russellville', 'Conway')
cities.insert('Carlisle', 'Russellville')
cities.insert('Alma', 'Carlisle')
cities.insert('adf', 'Carlisle')
// cities.display()
// cities.remove('Alma')
// cities.display()
// cities.remove('adf')
cities.display()
console.log('');
// cities.dispReverse()
cities.back(5)
cities.advance(3)
cities.show()













const canvas = document.querySelector('canvas')

const can = canvas.getContext('2d')


const down = new Image()
down.src = '../down.JPG'
down.onload = () => {
  can.drawImage(down, 0, 0)
}

const up = new Image()
up.src = '../up.JPG'

let flag = false
canvas.onmousedown = () => {
  flag = true
}

canvas.onmousemove = e => {
  if (flag) {
    can.drawImage(up, e.offsetX - 100, e.offsetY - 100, 100, 100, e.offsetX - 100, e.offsetY - 100, 100, 100)
  }
}

canvas.onmouseup = () => {
  flag = false
}

